<template>
  <view class="good-detail-container">
    <!-- 轮播图 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular="true">
      <swiper-item v-for="(item,i) in goods_info.pics">
        <image :src="item.pics_big"></image>
      </swiper-item>
    </swiper>
    <!-- 商品信息区 -->
    <view class="good-msg-box">
      <view class="price" v-if="goods_info.goods_price">￥{{goods_info.goods_price}}</view>
      <view class="msg">
        <view class="msg-name" v-if="goods_info.goods_name">{{goods_info.goods_name}}</view>
        <view class="favi">
          <uni-icons type="star" size="20"></uni-icons>
          <text>收藏</text>
        </view>
      </view>
      <view class="yunf">快递：免运费</view>
    </view>
    <!-- 商品介绍 -->
    <rich-text :nodes="goods_info.goods_introduce"></rich-text>
    <!-- 下方导航栏 -->
    <view class="goods-carts">
      <uni-goods-nav :options="options" :fill="true" :button-group="buttonGroup" @click="onClick"
        @buttonClick="buttonClick" />
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        //商品详情对象
        goods_info: {},
        options: [ {
          icon: 'shop',
          text: '店铺',
        }, {
          icon: 'cart',
          text: '购物车',
          info: 2
        }],
        buttonGroup: [{
            text: '加入购物车',
            backgroundColor: 'linear-gradient(90deg, #FFCD1E, #FF8A18)',
            color: '#fff'
          },
          {
            text: '立即购买',
            backgroundColor: 'linear-gradient(90deg, #FE6035, #EF1224)',
            color: '#fff'
          }
        ],

      };
    },
    onLoad(options) {
      this.getGoodsInfo(options.goods_id)
    },
    methods: {
      async getGoodsInfo(goods_id) {
        const {
          data: res
        } = await uni.$http.get('/api/public/v1/goods/detail', {
          goods_id
        })
        if (res.meta.status !== 200) return uni.$showMsg()
        res.message.goods_introduce = res.message.goods_introduce.replace(/<img /g, '<img style="display: block;" ')
        this.goods_info = res.message
      },
      onClick(e){
        console.log(e,'===========');
        if(e.content.text == "购物车"){
          uni.switchTab({
            url:"/pages/cart/cart"
          })
        }
      }
    }

  }
</script>

<style lang="scss">
  swiper {
    height: 750rpx;

    swiper-item,
    image {
      height: 100%;
      width: 100%;
    }
  }

  .good-msg-box {
    margin: 10px;

    .price {
      color: #c00000;
      font-size: 40rpx;

    }

    .msg {
      display: flex;
      justify-content: space-between;
      margin: 10rpx 0;

      .msg-name {
        width: 90%;
        padding: 0 10rpx;
        font-size: 13px;
      }

      .favi {
        width: 10%;
        display: flex;
        flex-direction: column;
        align-items: center;
        border-left: 1px solid #efefef;
        padding: 2px;

        text {
          color: grey;
          font-size: 12px;
        }
      }
    }

    .yunf {
      font-size: 24rpx;
      color: darkgrey;
    }
  }
  .goods-carts {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
  }
  .good-detail-container {
    padding-bottom: 50px;
  }
</style>